//
//  BNDOfficeDocReadVc.m
//  OfficeDoc
//
//  Created by pie on 2022/4/5.
//  Copyright © 2022 pie. All rights reserved.
//

#import "BNDOfficeDocReadVc.h"
#import "BNDOfficeDocReadListView.h"
#import "LKNavBarTitleMenu.h"
#import "BNDReadListHelper.h"
#import "BNDOfficeDocKit.h"

@interface BNDOfficeDocReadVc ()
@property (strong, nonatomic) LKNavBarTitleMenu *navBarTitleMenu;
@property (strong, nonatomic) UIScrollView *listScrollView;
@property (strong, nonatomic) NSMutableArray *helpeList;
@property (copy,   nonatomic) NSString *readCount;
@property (copy,   nonatomic) NSString *readHasBeenSigned;
@property (copy,   nonatomic) NSString *readUnsigned;
@property (copy,   nonatomic) NSString *unreadCount;
@end

@implementation BNDOfficeDocReadVc

- (instancetype)init:(NSString*)readCount readHasBeenSigned:(NSString*)readHasBeenSigned readUnsigned:(NSString*)readUnsigned
         unreadCount:(NSString*)unreadCount
{
    self = [super init];
    if(self){
        self.readCount = readCount;
        self.readHasBeenSigned = readHasBeenSigned;
        self.readUnsigned = readUnsigned;
        self.unreadCount = unreadCount;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    NSArray *array = @[[NSString stringWithFormat:@"已签%@",TTStringNilToZero(self.readHasBeenSigned)],[NSString stringWithFormat:@"未签%@",TTStringNilToZero(self.readUnsigned)],[NSString stringWithFormat:@"已读%@",TTStringNilToZero(self.readCount)],[NSString stringWithFormat:@"未读%@",TTStringNilToZero(self.unreadCount)]];
    self.navBarTitleMenu.titles = [NSMutableArray arrayWithArray:array];
    [self.view addSubview:self.navBarTitleMenu];
    [self.view addSubview:self.listScrollView];
    [self.navBarTitleMenu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(self.view.mas_top).offset(BNDNavigationBarHeight());
    }];
    
    _helpeList = [NSMutableArray array];
   
    @weakify(self)
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        @strongify(self)
        BNDOfficeDocReadListView *liveListView = [[BNDOfficeDocReadListView alloc] initWithFrame:CGRectMake(kDeviceWidth*idx, 0, kDeviceWidth, self.listScrollView.height)];
        liveListView.type = idx;
        liveListView.announcementId = self.announcementId;
        [self.helpeList addObject:liveListView];
        if(idx ==0) {
            [liveListView.helper reload];
        }
        [self.listScrollView addSubview:liveListView];
    }];
    
   _navBarTitleMenu.titles = [NSMutableArray arrayWithArray:array];
    _navBarTitleMenu.contentScrollView = self.listScrollView;
}


- (LKNavBarTitleMenu *)navBarTitleMenu
{
    if (!_navBarTitleMenu) {
        _navBarTitleMenu = [[LKNavBarTitleMenu alloc] initWithTitles:[NSArray array]];
        _navBarTitleMenu.menuStyle = BNDMenuStyleNone;
        [_navBarTitleMenu setContainerMaxWidth:kDeviceWidth-32];
        [_navBarTitleMenu setFirstButtonLeftMargin:0];

        [_navBarTitleMenu setTitleNormalFont:BNDPFRegularFont(14)];
        [_navBarTitleMenu setTitleSelectedFont:BNDPFHeavyFont(16)];
        [_navBarTitleMenu setTitleNormalColor:UIColorWithHex(0x959BA6)];
        [_navBarTitleMenu setTitleSelectedColor:UIColorWithHex(0x34363B)];
        [_navBarTitleMenu setButtonMargin:28];
        [_navBarTitleMenu setLineBottomMargin:0];
        [_navBarTitleMenu setLineMinWidth:20];
        [_navBarTitleMenu.sliderLine setBackgroundColor:UIColorWithHex(0x3770EB)];
        [_navBarTitleMenu setAlpha:1.0f];
        _navBarTitleMenu.backgroundColor = UIColor.redColor;
        _navBarTitleMenu.sliderLine.frame = CGRectMake(0,34, 16, 3);
        _navBarTitleMenu.backgroundColor = UIColor.clearColor;
        _navBarTitleMenu.layer.masksToBounds = YES;

        @weakify(self)
        [_navBarTitleMenu setMenuPressedButtonBlock:^(LKNavBarTitleMenu *headerView, NSInteger index){
            @strongify(self)
            BNDOfficeDocReadListView *liveListView  = [self.helpeList objectAtIndex:index];
            if(!liveListView.helper.loadOnce){
                [liveListView.helper reload];
            }
        }];
    }
    
    return _navBarTitleMenu;
}

- (UIScrollView *)listScrollView
{
    if (!_listScrollView) {
        _listScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,BNDNavigationBarHeight()+44, kDeviceWidth, kDeviceHeight- BNDNavigationBarHeight()-44)];
        _listScrollView.backgroundColor = UIColor.whiteColor;
        [_listScrollView setScrollsToTop:NO];
        [_listScrollView setPagingEnabled:YES];
        [_listScrollView setShowsHorizontalScrollIndicator:NO];
        [_listScrollView setContentSize:(CGSize){self.view.width*4,_listScrollView.height}];
    }
    return _listScrollView;
}

@end
